#!/bin/sh
#
# cmd -- Start any cmd in a container
#
# Copyright (C) 2016-2020 Wu Zhangjin <lzufalcon@163.com>
#


uname | grep -q MINGW && PWD_OPT="-W"
TOP_DIR="$(cd "$(dirname "$0")"/../../ && pwd $PWD_OPT)"
. "$TOP_DIR/tools/docker/config" $* >/dev/null

[ -z "$1" ] && echo "Usage: $0 [lab-name] cmd" && exit 0

cmd="$1"
[ -n "$2" ] && cmd="$2"

docker ps -f name=$CONTAINER_NAME | grep -qv PORTS
[ $? -ne 0 ] && echo "LOG: $LAB_NAME is not running." && exit 1

do_op "docker exec" CONTAINER_NAME "$cmd"
